package com.mind.invoice.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mind.common.annotation.Log;
import com.mind.common.web.controller.BaseController;
import com.mind.common.core.domain.AjaxResult;
import com.mind.common.enums.BusinessType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.mind.invoice.domain.AjReportFiles;
import com.mind.invoice.service.IAjReportFilesService;
import com.mind.common.utils.poi.ExcelUtil;
import com.mind.common.web.page.TableDataInfo;

/**
 * 附件Controller
 * 
 * @author today
 * @date 2025-04-25
 */
@RestController
@RequestMapping("/invoice/files")
@Tag(name = "附件管理", description = "附件管理")
public class AjReportFilesController extends BaseController
{
    @Autowired
    private IAjReportFilesService ajReportFilesService;

    /**
     * 查询附件列表
     */
    @PreAuthorize("@ss.hasPermi('invoice:files:list')")
    @GetMapping("/list")
    @Operation(summary = "查询附件列表", description = "查询附件列表")
    public TableDataInfo list(AjReportFiles ajReportFiles)
    {
        startPage();
        List<AjReportFiles> list = ajReportFilesService.selectAjReportFilesList(ajReportFiles);
        return getDataTable(list);
    }

    /**
     * 导出附件列表
     */
    @PreAuthorize("@ss.hasPermi('invoice:files:export')")
    @Log(title = "附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出附件列表", description = "查询附件列表")
    public void export(HttpServletResponse response, AjReportFiles ajReportFiles)
    {
        List<AjReportFiles> list = ajReportFilesService.selectAjReportFilesList(ajReportFiles);
        ExcelUtil<AjReportFiles> util = new ExcelUtil<AjReportFiles>(AjReportFiles.class);
        util.exportExcel(response, list, "附件数据");
    }

    /**
     * 获取附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('invoice:files:query')")
    @GetMapping(value = "/{id}")
    @Operation(summary = "获取附件详细信息", description = "获取附件详细信息")
    public AjaxResult getInfo(@Parameter(description ="附件Id",required=true) @PathVariable("id") Long id)
    {
        return success(ajReportFilesService.selectAjReportFilesById(id));
    }

    /**
     * 新增附件
     */
    @PreAuthorize("@ss.hasPermi('invoice:files:add')")
    @Log(title = "附件", businessType = BusinessType.INSERT)
    @PostMapping
    @Operation(summary = "新增附件", description = "新增附件")
    public AjaxResult add(@RequestBody AjReportFiles ajReportFiles)
    {
        return toAjax(ajReportFilesService.insertAjReportFiles(ajReportFiles));
    }

    /**
     * 修改附件
     */
    @PreAuthorize("@ss.hasPermi('invoice:files:edit')")
    @Log(title = "附件", businessType = BusinessType.UPDATE)
    @PutMapping
    @Operation(summary = "修改附件", description = "修改附件")
    public AjaxResult edit(@RequestBody AjReportFiles ajReportFiles)
    {
        return toAjax(ajReportFilesService.updateAjReportFiles(ajReportFiles));
    }

    /**
     * 删除附件
     */
    @PreAuthorize("@ss.hasPermi('invoice:files:remove')")
    @Log(title = "附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @Operation(summary = "删除附件", description = "删除附件")
    public AjaxResult remove(@Parameter(description ="附件Id",required=true) @PathVariable Long[] ids)
    {
        return toAjax(ajReportFilesService.deleteAjReportFilesByIds(ids));
    }
}
